import CryptoJS from 'crypto-js';

const _key_ = 'sd35r35d35fewqj5';
const _iv_ = 'w158w8sdbys73js9';

export function encrypt(text) {
  const key = CryptoJS.enc.Utf8.parse(_key_);
  const iv = CryptoJS.enc.Utf8.parse(_iv_);
  const value = CryptoJS.enc.Utf8.parse(text);

  const result = CryptoJS.AES.encrypt(value, key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });

  return CryptoJS.enc.Base64.stringify(result.ciphertext);
}

export function decrypt(text) {
  const key = CryptoJS.enc.Utf8.parse(_key_);
  const iv = CryptoJS.enc.Utf8.parse(_iv_);
  const value = CryptoJS.enc.Base64.parse(text);

  const result = CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(value), key, {
    iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });

  return result.toString(CryptoJS.enc.Utf8);
}
